home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 November: Tool Chest / Dev.CD Nov 98 TC.toast / Sample Code / Networking / OT PAPServerSample / SetServerStatusOption.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-08-28  |  2.8 KB  |  94 lines  |  [TEXT/CWIE]

  1. #include "OpenTransport.h"            // open transport files            
  2. #include "OpenTptAppleTalk.h"
  3.  
  4. /*
  5. **    prototype declaration
  6. */
  7. extern OSStatus DoSetServerStatusOption(EndpointRef ep, char *statusStr);
  8.  
  9.  
  10. /*
  11.     global variables
  12.     The nature of the following call is such that you'll want to set the option 
  13.     when the endpoint is in asynch mode.  To handle the asynch case, you must
  14.     declare the global gOptionCompleted.  When an option management call is made
  15.     gOptionCompleted is set to zero.  When the T_OPTMGMTCOMPLETE call is handled
  16.     by the endpoint handler, then gOptionCompleted is set to 1.  Note that the
  17.     sample spin loops until gOptionCompleted is non-zero.  As such, the 
  18.     DoSetServerStatusOption call cannot be made at interrupt time or from a deferred
  19.     task.  The DoSetServerStatusOption can only be made at system task time.
  20.     
  21.     Ensure that gOptionCompleted is used to flag only one outstanding Option 
  22.     Management call at a time.
  23.     
  24. */
  25. extern UInt32    gOptionCompleted;
  26.  
  27. /*
  28.     input parameters
  29.     ep - endpoint on which to set the status string option
  30.     statusstr - C style string of the status string to set
  31.     
  32.     function result - kOTNoError indicates that the option was successfully negotiated
  33.         if the result is negative, then this is the result returned by the call to
  34.         OTOptionManagement.  If the result is positive, then this is the value of 
  35.         the status field on return from the call to 
  36.  
  37. */
  38. OSStatus DoSetServerStatusOption(EndpointRef ep, char *statusStr)
  39.  
  40. {
  41.     UInt8        buf[kOTOptionHeaderSize+256];    // define buffer to allow for 
  42.                                                 // up to a 256 char string
  43.     TOption*    opt;                            // option ptr to make items easier to access
  44.     TOptMgmt    req;
  45.     TOptMgmt    ret;
  46.     UInt32         statusStrLen;
  47.     OSStatus    err;
  48.     Boolean        isAsync = false;
  49.     
  50.     if (OTIsSynchronous(ep) == false)            // check whether ep sync or not
  51.     {
  52.         isAsync = true;
  53.         gOptionCompleted = 0;
  54.     }
  55.     
  56.     statusStrLen = OTStrLength(statusStr);    // get the length of the C string        
  57.     opt = (TOption*)buf;                    // set option ptr to buffer
  58.     req.opt.buf    = buf;
  59.     req.opt.len    = kOTOptionHeaderSize + statusStrLen;
  60.     req.flags    = T_NEGOTIATE;                // negotiate for serverstatus option
  61.  
  62.     ret.opt.buf = buf;
  63.     ret.opt.maxlen = kOTOptionHeaderSize+256;
  64.     
  65.  
  66.     opt->level    = ATK_PAP;                    // dealing with tpi
  67.     opt->name    = OPT_SERVERSTATUS;
  68.     opt->len    = kOTOptionHeaderSize + statusStrLen;
  69.     opt->status = 0;
  70.         // set the serverStr into the value field
  71.     BlockMove(statusStr, (Ptr)&opt->value, statusStrLen);
  72.  
  73.     err = OTOptionManagement(ep, &req, &ret);
  74.     
  75.     if ((isAsync == true) && (err == kOTNoError))
  76.     {
  77.         while (gOptionCompleted == 0)
  78.         {
  79.             // spin in this null loop waiting for the option call to complete.
  80.         }
  81.     }
  82.     
  83.         // if no error then return the option status value
  84.     if (err == kOTNoError)
  85.     {
  86.         if (opt->status != T_SUCCESS)
  87.             err = opt->status;
  88.         else
  89.             err = kOTNoError;
  90.     }
  91.         
  92.     return err;
  93. }
  94.